<?php
/*
 * 编辑器草稿箱 的 json
 */
include '../../common.inc.php';
$table = Table::name(Table::NAME_MERCHANT_DRAFT);

//假如传过来的值aContent为真  进行存草稿的配置
if($aA == 'saveItemCache' && $aId && $aContent) {

	$content = $db->getOne("select content from $table where did=$aId");
	if($content) {
		$sql = Sql::update($table,array(
			'content'       => $aContent,
			'authorid'      => $_userid,
			'author'        => $_username,
			'time'          => time(),
		),'did='.$aId);

		if (!$db->query($sql)) 	exit($db->error());

		$arr['errNo'] = 0;
		echo json_encode($arr);

	}else{
		$sql = Sql::insert($table,array(
			'did'           => $aId,
			'content'       => $aContent,
			'authorid'      => $_userid,
			'author'        => $_username,
			'time'          => time(),
		));
		if (!$db->query($sql)) 	exit($db->error());
		$arr['errNo'] = 0;
		echo json_encode($arr);
	}


}


//假如传过来的公司ID为真 返回公司的草稿信息
if($aA == 'existItemCache' && $aId && $aAuthor){
	$sql = "select content from $table where did=$aId and author='$aAuthor'";

	if($content = $db->getVar($sql)) {
		$arr['errNo']       = 0;
		$arr['errMsg']      = 0;
		$arr['aContent']    = $content;
	}
	echo json_encode($arr);
}
